/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.bth.ke.firstfriend.depend;

import java.util.Set;

/**
 *
 * @author nico.rehwaldt
 */
public class AssociationRule {
    
    private final long target;
    private final Set<Long> base;
    private final double associationAccuracy;
    private final double baseAccuracy;
    
    /**
     * Creates a new association rule 
     * 
     * @param result
     * @param base
     * @param associationAccuracy
     * @param baseAccuracy 
     */
    public AssociationRule(long result, Set<Long> base, double associationAccuracy, double baseAccuracy) {
        this.target = result;
        this.base = base;
        this.associationAccuracy = associationAccuracy;
        this.baseAccuracy = baseAccuracy;
    }
    
    /**
     * @param set the set to check for an association match
     * @return true if the given set is matched by this association
     */
    public boolean matches(Set<Long> set) {
        return !set.contains(target) && set.containsAll(base);
    }
    
    /**
     * @return accuracy of the association
     */
    public double getAssociationAccuracy() {
        return associationAccuracy;
    }
    
    /**
     * @return the associated value
     */
    public long getTarget() {
        return target;
    }
   
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        return builder
            .append(target).append(" <- ").append(base)
            .append("  (").append(baseAccuracy).append(", ").append(associationAccuracy).append(")")
            .toString();
    }

    /**
     * @return the base
     */
    public Set<Long> getBase() {
        return base;
    }

    /**
     * @return the baseAccuracy
     */
    public double getBaseAccuracy() {
        return baseAccuracy;
    }
}
